package com.tiantianfresh.admin.controller;

import com.tiantianfresh.admin.service.OrderService;
import com.tiantianfresh.model.pojo.AJAXResult;
import com.tiantianfresh.model.pojo.OrderAddress;
import com.tiantianfresh.model.pojo.OrderSpecific;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author FANGAO
 * @date 2021/12/13 - 下午 14:33
 */
@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @RequestMapping("/goOrderAddress/{stateid}")
    public String goOrderAddress(@PathVariable Integer stateid,Model model) {
        model.addAttribute("stateid",stateid);
        return "order/index";
    }
    @ResponseBody
    @RequestMapping("/queryOrderAddress/{stateid}")
    public Object queryOrderAddress(@PathVariable Integer stateid) {
        AJAXResult result = new AJAXResult();
        List<OrderAddress> orderAddress = orderService.queryOrderAddress(stateid);
        if (orderAddress!=null){
            result.setData(orderAddress);
            result.setSuccess(true);
        }else{
            result.setSuccess(false);
        }
        return result;
    }
    @RequestMapping("/goOrderSpecific/{orderid}")
    public String goOrderSpecific(@PathVariable String orderid,Model model) {
        model.addAttribute("orderid",orderid);
        return "order/orderSpecific";
    }
    @ResponseBody
    @RequestMapping("/queryOrderSpecific/{orderid}")
    public Object queryOrderSpecific(@PathVariable String orderid) {
        AJAXResult result = new AJAXResult();
        List<OrderSpecific> orderSpecifics = orderService.queryOrderSpecific(orderid);
        if (orderSpecifics!=null){
            result.setData(orderSpecifics);
            result.setSuccess(true);
        }else{
            result.setSuccess(false);
        }
        return result;
    }
    @ResponseBody
    @RequestMapping("/updateOrderState")
    public Object updateOrderState(String orderid) {
        AJAXResult result = new AJAXResult();
        Map<String,Object> map = new HashMap<>();
        map.put("orderid",orderid);
        result.setSuccess(orderService.updateOrderState(map));
        return result;
    }
}
